package com.hnevn.newslist.Apdater;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.hnevn.newslist.Bean.NewsBean1;
import com.hnevn.newslist.MainActivity;
import com.hnevn.newslist.R;

import java.util.List;

public class NewsAdapter extends BaseAdapter {
    MainActivity content;
    List<NewsBean1.ResultDTO.DataDTO> list;

    public NewsAdapter(MainActivity content, List<NewsBean1.ResultDTO.DataDTO> list) {
        this.content = content;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null){
            convertView = View.inflate(content, R.layout.news_list,null);
        }
        ImageView mLvImage = convertView.findViewById(R.id.iv_image);
        TextView mTvTilte = convertView.findViewById(R.id.tv_title);
        TextView mTvTime = convertView.findViewById(R.id.tv_time);
        mTvTilte.setText(list.get(position).getTitle());
        mTvTime.setText(list.get(position).getDate());
        Glide.with(content).load(list.get(position).getThumbnail_pic_s()).into(mLvImage);
        return convertView;
    }
}
